package com.example.spring_source_code.bean.post;

import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
import org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor;
import org.springframework.context.annotation.CommonAnnotationBeanPostProcessor;
import org.springframework.context.annotation.ContextAnnotationAutowireCandidateResolver;
import org.springframework.context.support.GenericApplicationContext;

public class processor {
    public static void main(String[] args) {
        //这个容器中没有添加后置处理器，需要自己添加
        GenericApplicationContext context = new GenericApplicationContext();
        context.registerBean("bean01", Bean01.class);
        context.registerBean("bean02", Bean02.class);
        context.registerBean("bean03", Bean03.class);
        context.registerBean("bean04", Bean04.class);

        //需要配置这个解析Bean的@Value才能生效
        context.getDefaultListableBeanFactory().setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());
        //@Autowired @Value
        context.registerBean( AutowiredAnnotationBeanPostProcessor.class);
        // @Resource @PostContract @PreDestroy
        context.registerBean(CommonAnnotationBeanPostProcessor.class);
        //@ConfigurationProperties
        ConfigurationPropertiesBindingPostProcessor.register(context.getDefaultListableBeanFactory());
        //执行bean的后置处理器,添加bean后处理器，初始化所有单例
        context.refresh();

        Bean04 bean04 = context.getBean(Bean04.class);
        System.out.println(bean04);
        context.close();
    }
}
